/**
 * @description sequelize实例
 * @author 追追
 */

const Sequelize = require('sequelize');
const { MYSQL_CONF } = require('../conf/db');

const { host, user, password, database } = MYSQL_CONF;

const conf = {
    host,
    dialect: 'mysql',
};


const { isProd ,isTest} = require('../utils/env');


if(isTest){
    conf.logging = ()=>{};
}


// 线上环境 连接池
if (isProd) {
    conf.pool = {
        max: 5, //连接池最大的连接数
        min: 0, //最小的连接数量
        idle: 10000, //如果一个连接 10 s之内没使用，则释放
    };
}

const seq = new Sequelize(database, user, password, conf);

module.exports = seq;
